import ipV4address
import unittest

class TestIpV4(unittest.TestCase):
    def setUp(self):
        pass
    def tearDown(self):
        pass
    def testInstantiationWithIPAndMaskParms(self):
        t = ipV4address.ipaddress("192.168.20.132", "255.255.255.128")
        self.assertEqual(t.ipAsDotDec, "192.168.20.132")
        self.assertEqual(t.ipMaskAsDotDec, "255.255.255.128")
        self.assertEqual(t.ipSubnetAsDotDec, "192.168.20.128")
        
    def testInstantiationWithIPParm(self):
        t = ipV4address.ipaddress("192.168.20.132")
        self.assertEqual(t.ipAsDotDec, "192.168.20.132")
        self.assertEqual(t.ipMaskAsDotDec, "255.255.255.255")
        
    def testInstantiationWithIPAndMaskPrefix(self):
        t = ipV4address.ipaddress("192.168.0.0/24")
        self.assertEqual(t.ipAsDotDec, "192.168.0.0")
        self.assertEqual(t.ipMaskAsDotDec, "255.255.255.0")
        
    def testInstantiationWithIPAndMaskAsInt(self):
        t = ipV4address.ipaddress("10.0.0.0", 24)
        self.assertEqual(t.ipAsDotDec, "10.0.0.0")
        self.assertEqual(t.ipMaskAsDotDec, "255.255.255.0")
        
    def testIsPublic(self):
        t = ipV4address.ipaddress("10.0.0.1/32")
        self.assertEqual(t.isPublic(), False)

        t = ipV4address.ipaddress("11.0.0.1/32")
        self.assertEqual(t.isPublic(), True)

        t = ipV4address.ipaddress("172.16.0.1/32")
        self.assertEqual(t.isPublic(), False)
        
        t = ipV4address.ipaddress("172.32.0.1/24")
        self.assertEqual(t.isPublic(), True)
        
        t = ipV4address.ipaddress("192.168.0.1")
        self.assertEqual(t.isPublic(), False)
        
        t = ipV4address.ipaddress("192.167.254")
        self.assertEqual(t.isPublic(), True)
        
    def testIsPrivate(self):
        t = ipV4address.ipaddress("172.16.0.1/32")
        self.assertEqual(t.isPrivate(), True)
        
        t = ipV4address.ipaddress("172.32.0.1/24")
        self.assertEqual(t.isPrivate(), False)
        
    def testIsIn(self):
        t1 = ipV4address.ipaddress("10.0.0.0", 8)
        t2 = ipV4address.ipaddress("10.0.0.1", 24)
        self.assertTrue(t2.isIn(t1))

        t1 = ipV4address.ipaddress("10.0.0.0", 24)
        t2 = ipV4address.ipaddress("10.0.0.1", 24)
        self.assertTrue(t2.isIn(t1))

        t1 = ipV4address.ipaddress("192.168.2.0", 24)
        t2 = ipV4address.ipaddress("10.0.0.1", 24)
        self.assertFalse(t2.isIn(t1))

if __name__ == '__main__':
    unittest.main()
